<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index()
    {
        //获取分类信息
        $cate_info = D('Cate')
            ->where(array('is_show'=>'0'))
            ->select();
        $this->assign('cate_info',$cate_info);
        //获取blog中总的条数
        $rows = D('Blog')->count();
        //每页的条数
        $per = 3;
        //引入分页类
        $page = new \Think\Page($rows,$per);
        //分页类配置
        $page->setConfig('header','共 %TOTAL_ROW% 条记录');
        $page->setConfig('prev','<<');
        $page->setConfig('next','>>');
        $page->setConfig('first','1...');
        $page->setConfig('last','...%TOTAL_PAGE%');
        $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
        $pagelist = $page->show();
        //首页展示分类博文列表信息
        $blog_info = D('Blog as b')
            ->join('bg_cate as c on b.cate_id=c.cate_id')
            ->where("b.is_show = '0'")
            ->limit($page->firstRow.','.$page->listRows)
            ->select();

        //获取最新8条博文内容
        $news_blog = D('Blog as b')
            ->join('bg_cate as c on b.cate_id=c.cate_id')
            ->where("b.is_show = '0'")
            ->order('blog_id desc')
            ->limit('8')
            ->select();
        //获取全部的图片信息
        //获取相册列表中前4个相册
        $pics_info = D('pics as p')
            ->join('bg_cate as c on p.cate_id=c.cate_id')
            ->order('pics_id desc')
            ->limit(6)
            ->select();
        $this->assign('pics_info', $pics_info);
        $this->assign('pics_info',$pics_info);
        $this->assign('news_blog',$news_blog);
        $this->assign('pagelist',$pagelist);
        $this->assign('blog_info',$blog_info);
        $this->display();
    }
}